package com.zzl.myblog.Utils;

import android.text.TextUtils;

import com.google.gson.Gson;
import com.zzl.myblog.Bean.ResponseBean.BannerBean;
import com.zzl.myblog.Bean.ResponseBean.NavigationDataBean;
import com.zzl.myblog.Bean.ResponseBean.SystemBean;
import com.zzl.myblog.Bean.ResponseBean.TopArticleBean;
import com.zzl.myblog.Bean.ResponseBean.UserBean;
import com.zzl.myblog.Bean.ResponseBean.UserCollectArticleBean;

public class responseUtility {
    public static final Gson gson = new Gson();

    /**
     * 解析 登录，注册JSON
     **/
    public static UserBean parse_user(String response){
        //是否为空
        if(!TextUtils.isEmpty(response)){
            try {
               return gson.fromJson(response, UserBean.class);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        return null;
    }

    /**
     * 解析 轮播图JSON
     */
    public static BannerBean parse_banner(String response){
        if(!TextUtils.isEmpty(response)){
            try {
                return gson.fromJson(response,BannerBean.class);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        return null;
    }

    /**
     * 解析 首页文章
     */
    public static TopArticleBean parse_TopArticles(String response){
        if(!TextUtils.isEmpty(response)){
            try {
                return gson.fromJson(response,TopArticleBean.class);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        return null;
    }

    /**
     * 解析 知识体系
     */
    public static SystemBean parse_initTree(String response){
        if(!TextUtils.isEmpty(response)){
            try {
                return gson.fromJson(response,SystemBean.class);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        return null;
    }

    /**
     * 解析 拓维导航
     */
    public static NavigationDataBean parse_initNavigation(String response){
        if(!TextUtils.isEmpty(response)){
            try {
                return gson.fromJson(response,NavigationDataBean.class);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        return null;
    }

    /**
     * 获取用户收藏的文章
     */
    public static UserCollectArticleBean parse_UserCollectArticleBean(String response){
        if(!TextUtils.isEmpty(response)){
            try {
                return gson.fromJson(response,UserCollectArticleBean.class);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        return null;
    }
}